From 04c30d61d84c762c8864b9f788abdc96058cfe02 Mon Sep 17 00:00:00 2001 From: Geoffry Song Date: Thu, 21 Sep 2017 23:04:17 -0700 Subject: [PATCH] Use memoized hashes when hashing Fingerprint. The recursive hashing of dependencies can cause exponential blowup. We already have a memoized hash available, so use that, Merkle-tree-style. --- src/cargo/ops/cargo_rustc/fingerprint.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_rustc/fingerprint.rs b/src/cargo/ops/cargo_rustc/fingerprint.rs index 38cef8f1c..e4d2dd124 100644 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@ -297,7 +297,14 @@ impl hash::Hash for Fingerprint { memoized_hash: _, ref rustflags, } = *self; - (rustc, features, target, profile, deps, local, rustflags).hash(h) + (rustc, features, target, profile, local, rustflags).hash(h); + + h.write_usize(deps.len()); + for &(ref name, ref fingerprint) in deps { + name.hash(h); + // use memoized dep hashes to avoid exponential blowup + h.write_u64(Fingerprint::hash(fingerprint)); + } } } -- 2.30.2